package org.gdstash.ui.font;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import java.awt.*;

public class BorderListCellRenderer<E extends String> implements ListCellRenderer<String> {
    private Border insetBorder;
    private DefaultListCellRenderer defaultRenderer;

    public BorderListCellRenderer(final int rightMargin) {
        this.insetBorder = new EmptyBorder(0, 2, 0, rightMargin);
        this.defaultRenderer = new DefaultListCellRenderer();
    }

    @Override
    public Component getListCellRendererComponent(final JList<? extends String> list, final String value, final int index, final boolean isSelected, final boolean cellHasFocus) {
        final JLabel renderer = (JLabel) this.defaultRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        renderer.setBorder(this.insetBorder);
        return renderer;
    }
}
